<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
	String basePath = request.getScheme()+"://"+request.getServerName()
		+ ":"+ request.getServerPort() + request.getContextPath() + "/";
%>
 
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<meta charset="UTF-8">
<title>部门列表信息</title>
</head>
<body>
<a href="user/logout.do">退出登录</a>
<h1 style="text-align:center">部门列表</h1>
	<!-- <form id="search">
		关键字:<input type="text" name="key">
		<input type="submit" value="查询">
	</form>
	<br> -->
	<table border="1" width="100%">
		<thead>
			<tr>
				<th>ID</th>
				<th>部门名</th>
				<th>办公室</th>
				<th>电话</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		
		</tbody>
		
	</table>
	
	<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
	<script type="text/javascript">
	
		searchDept();
	
		$("#search").submit(function(){
			
			//异步提交
			var key = $("input[name='key']").val();
			
			searchDept(key);
			
			return false;
			
		});

		//获取部门信息
		function searchDept(key){
			
			$.ajax({
				url: "dept/search.json",
				data: {},
				type: "post",
				dataType: "json",
				success: function(data){
					//遍历data
					var html = "";
					$.each(data,function(index,item){
						html += "<tr>"+
							"<td>"+item.did+"</td>"+
							"<td>"+item.dname+"</td>"+
							"<td>"+item.droom+"</td>"+
							"<td>"+item.dphone+"</td>"+
							"<td>"+
								"<a href='dept/modify.do?did="+item.did+"'>修改</a> "+
								"<a href='dept/remove.do?did="+item.did+"'>删除</a>"+
							"</td>"+
							"</tr>";
					});
					
					$("tbody").html(html);
					
				},
				error: function(){
					
				}
			});
		}
		
	</script>
</body>
</html>